<html>
<head>
<meta> <meta name="renderer" content="webkit">
<meta charset="UTF-8">
	<style>
		.discount-hover { cursor: pointer;}
	</style>
<style>
.col-center-block {
float: none;
display: block;
	 margin-left: auto;
	 margin-right: auto;
}
.center {
  width: auto;
  display: table;
  margin-left: auto;
  margin-right: auto;
  font-weight:bold;
}
.text-center {
  text-align: center;
}
</style>
</head>
<?php
	include './header.php';
	include './query.php';

	//use database;
	session_start();

	if(! $_SESSION['username']) {
		header('Location: /wine/login.php');
	}
?>


<body>

<!--
	<div class="container-fluid">
		<h1> </h1>
        <h1>微信营销后台管理系统</h1>
	</div>
-->


<div class="center">
  <h1>微信营销后台管理系统</h1>
</div>

  <div class="alert alert-success" role="alert">
        <h1>会员列表</h1>
    </div>
<p class=text-primary></p>

<form action="" method="GET" >

  <div class="form-group">
    <label for="搜索">模糊查找</label>
    <!--<span class="input-group-addon" id="basic-addon1">模糊搜索</span>-->
    <input type="text" class="form-control" id="keyword" placeholder="关键字" name="keyword"  />
	<input type="submit"  value="搜索"  class="btn-primary btn"/>
  </div>


<div class="bs-docs-example">

	<table class="table">
	<tr>
		<th>姓名</th>
		<th>手机</th>
		<th>性别</th>
		<th>折扣</th>
		<th>优惠券</th>
		<th>消费</th>
		<th>注册时间</th>
	</tr>

		<?php
				$keyword = $_GET['keyword'];
				$users = query_member_with_like($keyword);
				$style = array("success", "warning", "info");
				$index = 0;
				foreach($users as $key => $val) {
					$color = $style[$index];
					echo sprintf("<tr class=\"%s\"><td>%s</td><td>%s</td><td>%s</td><td class='discount-td discount-hover'  data-phone='%s' data-toggle=\"modal\" data-target=\"#myModal\" >%s</td><td data-phone='%s' data-toggle=\"modal\" data-target=\"#cuponModal\" class='discount-hover cupon-td'>%s</td><td class='amount-td'>%s</td><td>%s</td></tr>",$color,$val['name'], $val['phone'], $val['sex'] == 1 ? '男' : '女', $val['phone'], $val['discount'], $val['phone'], $val['coupon'], $val['consume'], $val['gmt_create']);
					$index = ++$index % count($style);
				}
		?>

	</table>
</div>

</form>

<div style="margin-top: 60px;"></div>



<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">修改折扣</h4>
      </div>
      <div class="modal-body">

		 <div class="form-group">
			<label for="">新折扣</label>
			<input type="hidden" name="discount-phone" id="discount-phone" value="" />
			<input type="text" class="form-control" id="discount" placeholder="输入新的折扣" name="discount"  />
		  </div>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default discount-modal-close" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary discount-save">保存</button>
      </div>
    </div>
  </div>
</div>


<div class="modal fade" id="cuponModal" tabindex="-1" role="dialog" aria-labelledby="cuponModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="cuponModalLabel">修改优惠</h4>
      </div>
      <div class="modal-body">

		 <div class="form-group">
			<label for="">新优惠</label>
			<input type="hidden" name="cupon-phone" id="cupon-phone" value="" />
			<input type="text" class="form-control" id="cupon" placeholder="输入新的优惠" name="cupon"  />
		  </div>

      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary cupon-save">保存</button>
      </div>
    </div>
  </div>
</div>

<form action="/wine/purchase.php" method="POST">
  <div class="form-group">
        <h1></h1>
  <div class="alert alert-danger" role="alert">
        <h1>消费登记</h1>
    </div>
    <input type="text" class="form-control" id="phone" name="phone" placeholder="电话">
	<input type="text" class="form-control" id="amount" name="amount" placeholder="金额">
	<select class="form-control" id="auction" name="auction">
		<?php
			$goods = get_all_goods();

			foreach($goods as $key => $val) {
				echo sprintf('<option value="%s">%s</option>', $val['name'], $val['name']);
			}
		?>
	</select>
	<input name="count" type="text" class="form-control" id="count" placeholder="销量">
	<!--
	<input type="text" class="form-control" id="introducerPhone" placeholder="推荐人手机号">
	-->
  </div>
  <button type="submit" class="btn btn-success">增加消费</button>
</form>



</body>

<script>

	
	$('.discount-td').on('click', function() {
		$('#discount-phone').val($(this).attr('data-phone'));
	});

	$('.cupon-td').on('click', function() {
		$('#cupon-phone').val($(this).attr('data-phone'));
	});

	// 修改折扣
	$('.discount-save').on('click', function() {
		var update_discount_url = '/wine/update_discount.php';
		var post_data = {};
		post_data.discount = $('#discount').val();
		post_data.phone = $('#discount-phone').val();
		$.post(update_discount_url, post_data, function(res){
			// TODO
			if (res != 'ok') {
				alert('输入错误')
			}
			location.href = location.href;
		});
	});

	// 修改优惠
		$('.cupon-save').on('click', function() {
		var update_cupon_url = '/wine/update_cupon.php';
		var post_data = {};
		post_data.cupon = $('#cupon').val();
		post_data.phone = $('#cupon-phone').val();
		$.post(update_cupon_url, post_data, function(res){
			if (res != 'ok') {
				alert('输入错误')
			}
			location.href = location.href;
		});
	});

</script>

</html>	

